Why does my nested SQL SELECT returns either null or 'more than one row'